<?php
defined('IN_PHPCMS') or exit('No permission resources.');
/**
 * 超市加盟申请接口
 */

$joinApplyDb = pc_base::load_model('join_apply_model');
$name = '';
$age = 0;
$investment = 0;
$mobile = '';
$verifyCode = 0;

$name = $_POST['name'];
$age = intval($_POST['age']);
$investment = intval($_POST['investment']);
$mobile = $_POST['mobile'];
$verifyCode = strval($_POST['verifyCode']);

//验证中文名字
if(!preg_match('/^[\x7f-\xff]+$/', $name)){
    echo json_encode('无效的名字');die;
}
if($age > 150 || $age < 1){
    echo json_encode('年龄不合法');die;
}
if($investment < 1){
    echo json_encode('投资数必须正整数');die;
}
if(strlen($mobile) != 11 || !preg_match('/^1[34578]\d{9}$/', $mobile)){
    echo json_encode('手机号码错误');die;
}

if(!preg_match('/^[0-9]{6}$/', $verifyCode)){
    echo json_encode('验证码错误');die;
}

$checkVerifyCode = pc_base::load_model('sms_report_model');
//5分钟有效时间
$lostTime = time() - 5*60;
$check = $checkVerifyCode->count(" id_code=$verifyCode and mobile='$mobile' and posttime>$lostTime");
if(!$check){
    echo json_encode('验证码无效');die;
}
$insertData = array(
    'name' => $name,
    'age' => $age,
    'investment' => $investment,
    'mobile' => $mobile,
    'create_time' => time()
);
echo 0;die;
$result = $joinApplyDb->insert($insertData);
if($result){
    echo 0;
}

?>